<?php
class yc_jiance extends spController
{

	//主检测模块http检测
	function __construct(){ 
		parent::__construct(); 
	}
	function index(){
		$this->display("produce/main_index.html");
	}
	
	function page(){
		$this->start_detection();
		$this->display("produce/main_page.html");
	}
	function start_detection()
	{
		$time = $this->spArgs('time');
		$this->moniter($time);
	}

	/**
	 +----------------------------------------------------------
	 * 网站状态测试
	 +----------------------------------------------------------
	 */
	public function http_p($url,$method,$postDate)
	{
		 
		$method ='GET';
		$postDate = '';
		import("WebRequest.php");
		$ht_tp = new WebRequest($url,$method,$postDate);

		if (!$c=$ht_tp->getResponse())
		{
			return 'could not open';
		}
		else
		{
			return $c->status;
		}
	}

	/**
	 +----------------------------------------------------------
	 * 循环
	 +----------------------------------------------------------
	 */

	private function moniter($time)
	{
		ignore_user_abort(); 
		set_time_limit(0); 
		$interval= $time;
		date_default_timezone_set("Asia/Shanghai"); 
		do
		{
			$this->detection($interval);
			sleep($interval);

		}while(true);
	}
	/**
	 * ////
	 * Enter description here ...
	 * @param unknown_type $siteid
	 */
	function alarm($siteid)
	{
		$record = spClass('record');
		$n = $record->etc($siteid);
		if($n[0][status_code]=200){
			if($n[1][status_code]=200){
				break;
			}else{
				$time = $n[0][addtime]-$n[1][addtime];
			}
		}
		else{
			if ($n[1][status_code]=200){
				$time = $n[0][addtime]-$n[1][addtime];
			}
			else{
				break;
			}
		}
	}
	/**
	 * 模拟访问
	 */
	function ffp($path) 
	{
		$domain = "www.speed-1.com";//写入主网站域名
		$fp = fsockopen ( "$domain", 80, $errno, $errstr, 30 );
		if (! $fp){
			echo "$errstr ($errno)<br />\n";
		} else{
			$header = "GET /$path HTTP/1.1\r\n";
			$header .= "Host:  $domain\r\n";
			$header .= "Connection: Close\r\n\r\n";
			fwrite ( $fp, $header );
			fclose ( $fp );
			return true;
		}
	}
	/**
	 * 远程访问(检测)
	 */
	function y_f()
	{
		$data=$this->spArgs();
		$s_date = date("Y-m-d H:i:s");
		$status=$this->http_p($data[domain]);
		$n_date = date("Y-m-d H:i:s");
		$sb=strtotime($n_date)-strtotime($s_date);

		import("detection.php");
		$get_ip = new detection();
		$ip=$get_ip->g_ip($data[domain]);
		unset($get_ip);
		$dat=array(
			c=>"yc_http",
			a=>"huoqu",
			siteid=>$data["siteid"],
			status=>$status,
			time=>$sb,
			ip=>$ip,
			stationid=>1
		);
		$shuju="produce.php?";
		foreach($dat as $k => $v){
   		 $shuju .= $k . "=" . $v . "&";
		};

		$this->ffp($shuju);
	}

	function paost(){
		$data=$this->spArgs();
		dump($data);
		//$qqw=$_POST;
		//dump($qqw);
	}
}